<template>
    <div class="allHouses hasFoot ">
     <HeaderNav3 :activeIndex="activeIndex"></HeaderNav3>
        <Contact></Contact>
        <Ad></Ad>
        <ul class="allHouses-item wrap">
            <li v-for="item in items">
                <router-link :to="{path:'/housingDetails',query:{id:item.id}}">
                    <img :src="item.more">
                    <p>
                        {{item.post_title}}
                    </p>
                    <div class="item-hr"></div>
                </router-link>
                
            </li>
        </ul>
        <div class="allHouses-page ">     
          <el-pagination
            layout="prev, pager, next"
            @current-change="handleCurrentChange"
            :total="totalCount" >
          </el-pagination>
        </div>
        
       

    </div>
        
</template>

<script>
import HeaderNav3 from "@/components/HeaderNav3.vue"
import Contact from '@/components/Contact.vue'
import Ad from '@/components/Ad.vue'
import { V1_ESTATE_LIST} from "@/config/api"
export default {
	components:{
        Contact,
        Ad,
        HeaderNav3
	},
    mounted(){
       
        // console.log(this.$route.query.search);
        if(this.$route.query.search){
           this.searchData();
           
        }else{
               this.getData();
        }
    },
    activated(){ 
        this.$store.commit("IS_SHOW_ALERT",true)
    },  
    methods:{
        getData(){
            /*1、type: 0：不分类
                         1：网友热论
                         2：热门成交
                2、keyword：按关键词搜索
                3、page：当前列表翻页索引
                4、page_size：定义列表页面数量大小*/
                this.$http.get(V1_ESTATE_LIST+0+"/"+0+"/"+(this.currentPage|0)+"/"+9,{
                }).then(res=>{
                    if(res.data.success){
                        this.items=res.data.infor.listItems;
                        this.totalCount = Math.ceil(res.data.infor.totalCount/9)*10;
                         // console.log(this.totalCount)
                    }
                })
        },
        searchData(){
            this.$http.get(V1_ESTATE_LIST+0+"/"+this.$route.query.keyword+"/"+(this.currentPage|0)+"/"+9,{
            }).then(res=>{
                if(res.data.success){
                    this.items=res.data.infor.listItems;
                    this.totalCount = Math.ceil(res.data.infor.totalCount/9)*10;
                    
                }
            })
        },
        handleCurrentChange(page) {
            this.currentPage = page-1;
            this.getData();
        },        
    },
    data(){
        // this.getData();
        // this.searchData();
       return{
            current:1,
            showItem:5,
            allpage:13,
            currentPage:0,
            "items":[],
            "totalCount":0,
            "activeIndex":"2",
       }
    },
}
</script>
<style lang="scss">
    @import "../style/allHouses";
    
</style>